import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @program: 2022.3.7复习
 * @description:
 * @author: 李鑫月
 * @create: 2022-03-10 08:54
 **/
class Card{
    private String rank;
    private int suit;

    public Card(String rank, int suit) {
        this.rank = rank;
        this.suit = suit;
    }

    public String getRank() {
        return rank;
    }

    public void setRank(String rank) {
        this.rank = rank;
    }

    public int getSuit() {
        return suit;
    }

    public void setSuit(int suit) {
        this.suit = suit;
    }

    @Override
    public String toString() {
        return "[花色:" +
                "rank=" + rank +
                ", 数字suit='" + suit + '\'' +
                ']';
    }
}
public class Test {
    private static final String[] ranks={"♥","♠","♣","♦"};
    public static List<Card> buyCard(){
        List<Card> list=new ArrayList<>();
        for (int i = 0; i <4 ; i++) {
            for (int j = 1; j <=13 ; j++) {
                String rank=ranks[i];
                int suit=j;
                Card card=new Card(rank,suit);
                list.add(card);
            }
        }
        return list;
    }
    private static  void swap(List<Card> cards,int i,int j){
        Card tmp=cards.get(i);
        cards.set(i,cards.get(j));
        cards.set(j,tmp);
    }
    public static void shuffle(List<Card> cards){
        int size=cards.size();
        for (int i = size-1; i >0; i--) {
            Random random=new Random();
            int randdomIndex=random.nextInt(i);
            swap(cards,i,randdomIndex);
        }
    }
    public static void main(String[] args) {
//        买牌
        List<Card> cards=buyCard();
//        洗牌
        shuffle(cards);
        System.out.println(cards);
//        发牌
        ArrayList<List<Card>> hand=new ArrayList<>();

        List<Card> hand1=new ArrayList<>();
        List<Card> hand2=new ArrayList<>();
        List<Card> hand3=new ArrayList<>();
        hand.add(hand1);
        hand.add(hand2);
        hand.add(hand3);
        for (int i = 0; i <5 ; i++) {
            for (int j = 0; j <3 ; j++) {
                    Card card=cards.remove(0);
                    hand.get(j).add(card);
            }

        }
        System.out.println("第一个人的牌"+hand1);
        System.out.println("第二个人的牌"+hand2);
        System.out.println("第三个人的牌"+hand3);
        System.out.println("剩下的人的牌"+hand);
    }
    public static void main1(String[] args) {
       Card card1=new Card("♥",3);
       Card card2=new Card("♥",3);
       Card card3=new Card("♥",3);
       Card card4=new Card("♥",3);
        System.out.println(card1);
    }
}
